<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of registers
 *
 * @author chandu
 */
include "base.php";
include CONFIG_PATH . 'errors.php';

class registers extends baseController {

    private $registers;
    private $mod;
    private $errors;

    public function __construct() {
        parent::__construct();
        $this->mod = new model();
        $this->errors = new errors();
        $this->registers = new registers_model();
        if (!$_SESSION) {
            echo '<script>window.location.assign("index.php")</script>';
        }
    }

    public function invoke() {
          //this code is to add registers if user have add permissions
        if (isset($_GET['add'])) {
            $this->data = $_GET['add'];
            if (($_SESSION['Addd'] == "Yes") or ($_SESSION['admin'] == 1)) {

                if (isset($_POST['registers'])) {
                    $reslt = $this->mod->add($this->tables->table5, $_POST, "register");
                    if ($this->reslt == "Success") {
                        $msg = $this->errors->module_inserted_successfully;
                        echo ("<SCRIPT LANGUAGE='JavaScript'>
                       window.alert('$msg');
                      </SCRIPT>");
                    } else if ($this->reslt == "Failed") {
                        $msg = $this->errors->default_failed;
                        echo ("<SCRIPT LANGUAGE='JavaScript'>
                       window.alert('$msg');
                      </SCRIPT>");
                    } else {
                        $msg = $this->errors->module_already_exists;
                        echo ("<SCRIPT LANGUAGE='JavaScript'>
                       window.alert('$msg');
                      </SCRIPT>");
                    }
                }
                $this->modules = $this->manage_users->get_modules($this->tables->table4);
                $this->show("registers/registers");
            } else {
                //this code will run if user doesnt have add permission
                $msg = $this->errors->access_denied;
                echo ("<SCRIPT LANGUAGE='JavaScript'>
                       window.alert('$msg');
                      </SCRIPT>");
                echo '<SCRIPT LANGUAGE="JavaScript">
                         window.location="manage_users.php";
                        </script>';
            }
        } else {
            $msg = $this->errors->invalidrequest;
            echo ("<SCRIPT LANGUAGE='JavaScript'>
                       window.alert('$msg');
                      </SCRIPT>");
        }






        $this->show("registers/index");
    }

}

$obj = new registers();
$obj->invoke();
?>